using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AgileFx.ORM;
using AgileFx.ORM.Providers.EntityViewProviders;

using projectNS = Debugging.Models;
using intermediateNS = Debugging.Models.Intermediate;
using L2SNS = Debugging.Models.L2S;

namespace Debugging.Models
{
	public class ItemMapping : ModelEntityMapping<projectNS.Item, intermediateNS.Item, L2SNS.Item>
	{
		public ItemMapping()
		{
			AddIdentityField<long>(e => e.Id); 
			AddRelationship<projectNS.Customer>(e => e.Customer, e => e.Items);
		}
	}
		
	[ClassMapping(typeof(ItemMapping))]
	public partial class Item : IEntityView<intermediateNS.Item>	
	{
		private intermediateNS.Item __intermediateEntity;
		public intermediateNS.Item _intermediateEntity { get { return __intermediateEntity; } }
		public IntermediateEntity _getIntermediateEntity() { return __intermediateEntity; }
		
		//Fields		
		public long Id 
		{	
			get { return _intermediateEntity.Id; }
			set { _intermediateEntity.Id = value; }
		}
		public long CustomerId 
		{	
			get { return _intermediateEntity.CustomerId; }
			set { _intermediateEntity.CustomerId = value; }
		}
			
		//Navigation Properties
		public Customer Customer 
		{	
			get { return _intermediateEntity.Customer.GetEntityView(); }
			set { if (value != null) _intermediateEntity.Customer = value._intermediateEntity; else _intermediateEntity.Customer = null; }
		}
		public Item() : this(new intermediateNS.Item())
		{
		}
			
		public Item(intermediateNS.Item intermediateEntity)		{
			__intermediateEntity = intermediateEntity;
			__intermediateEntity._entityView = this;
		}		

		public static bool operator ==(Item a, Item b)
		{
			return a._equals(b);
		}
		
		public static bool operator !=(Item a, Item b)
		{
			return !a._equals(b);
		}
		
		public override bool Equals(System.Object obj)
		{
			return ((Item)this)._equals(obj as Item);
		}
	}
}
	
namespace Debugging.Models.Intermediate
{
	public class Item : IntermediateEntity<projectNS.Item, L2SNS.Item>
	{		
			
		//Fields				
		public long Id 
		{	
			get { return __tableEntity.Id; }
			set { __tableEntity.Id = value; }
		}
		public long CustomerId 
		{	
			get { return __tableEntity.CustomerId; }
			set { __tableEntity.CustomerId = value; }
		}


		//Navigation Properties
		public EntityViewReference<projectNS.Item, projectNS.Customer, intermediateNS.Item, intermediateNS.Customer, L2SNS.Item, L2SNS.Customer> _customer;
		public intermediateNS.Customer Customer
		{	
			get { return _customer.Value; }
			set { _customer.Value = value; }
		}
		
		//Inherited Navigation Properties
						
		public Item()
		{
			__tableEntity = new L2SNS.Item();
			initFields();
		}
			
		public Item(L2SNS.Item tableEntity)
		{
			__tableEntity = tableEntity;
			initFields();
		}

		private void initFields()
		{
			_customer = new EntityViewReference<projectNS.Item, projectNS.Customer, intermediateNS.Item, intermediateNS.Customer, L2SNS.Item, L2SNS.Customer>(this, __i => __i.Customer, (__i, __customer) => __i.Customer = __customer, (__customer, __i) => __customer._items.AddReverseReference(__i), (__customer, __i) => __customer._items.RemoveReverseReference(__i));
		}
	}
}
	
namespace Debugging.Models.L2S
{
	partial class Item : ITableEntity<intermediateNS.Item>
	{
        public intermediateNS.Item _intermediateEntity { get; set; }
	
		public IntermediateEntity _getIntermediateEntity()
		{
			return _intermediateEntity;
		}		
			
		public void _setIntermediateEntity(IntermediateEntity intermediateEntity)
		{
			_intermediateEntity = intermediateEntity as intermediateNS.Item;
		}
	}
}

